package com.hangzhou.welbeing.welbeinginstrument.activity;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.widget.LinearLayoutManager;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.hangzhou.welbeing.welbeinginstrument.R;
import com.hangzhou.welbeing.welbeinginstrument.adapter.HotVideoAdapter;
import com.hangzhou.welbeing.welbeinginstrument.fragement.HottestFragment;
import com.hangzhou.welbeing.welbeinginstrument.fragement.LatestFragment;
import com.hangzhou.welbeing.welbeinginstrument.utils.Utils;
import com.jcodecraeer.xrecyclerview.ProgressStyle;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


/**
 * 时间 2017 年 08 月 27 日
 * 作者  Z2043 welbeing to hangzou com.hangzhou.welbeing.pregnant.welbeing_pregnant.activity
 *
 * @desc 热门视频
 */
public class HotVideoActivity extends FragmentActivity {
    @Bind(R.id.activity_articles_iv_return)
    ImageView mActivityArticlesIvReturn;
    @Bind(R.id.activity_hot_video_xrecyclerView)
    XRecyclerView mActivityHotVideoXrecyclerView;
    @Bind(R.id.activity_hot_video_rl_news)
    RelativeLayout mActivityHotVideoRlNews;
    @Bind(R.id.activity_hot_video_hot)
    RelativeLayout mActivityHotVideoRlHot;
    @Bind(R.id.activity_hot_video_fl_content)
    FrameLayout mActivityHotVideoFlContent;
    private LatestFragment latestFragment;
    private LatestFragment latestFragment1;
    private HottestFragment hottestFragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hot_video);
        ButterKnife.bind(this);


        Utils.setStatusBar(this,false,false);
        Utils.setStatusTextColor(true,this);

        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mActivityHotVideoXrecyclerView.setLayoutManager(layoutManager);
        mActivityHotVideoXrecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
        mActivityHotVideoXrecyclerView.setLoadingMoreProgressStyle(ProgressStyle.BallRotate);

        mActivityHotVideoXrecyclerView.setPullRefreshEnabled(false);
        HotVideoAdapter hotVideoAdapter =  new HotVideoAdapter();
        mActivityHotVideoXrecyclerView.setAdapter(hotVideoAdapter);
        latest();
    }

    @OnClick({R.id.activity_articles_iv_return,R.id.activity_hot_video_rl_news,R.id.activity_hot_video_hot})
    public void onViewClicked(View view) {
        switch (view.getId()){
            case R.id.activity_articles_iv_return:
                finish();
            break;
            case R.id.activity_hot_video_rl_news:
                latest();
                break;
            case R.id.activity_hot_video_hot:
                hottest();
                break;
        }
    }
    /**
     * @desc 最新Fragment
     * */
    private void latest() {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        /**
         * 为了防止重叠，需要点击之前先移除其他Fragment
         */
        if(latestFragment1 != null){
            transaction.remove(latestFragment1);
        }

        latestFragment1 = new LatestFragment();
        transaction.replace(R.id.activity_hot_video_fl_content, latestFragment1);
        transaction.commit();
    }
    /**
     * @desc 最热Fragment
     * */
    private void hottest() {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction transaction = fragmentManager.beginTransaction();
        /**
         * 为了防止重叠，需要点击之前先移除其他Fragment
         */
        if(hottestFragment != null){
            transaction.remove(hottestFragment);
        }

        hottestFragment = new HottestFragment();
        transaction.replace(R.id.activity_hot_video_fl_content, hottestFragment);
        transaction.commit();
    }

}
